/*     */ package com.zimbra.qa.unittest.prov;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.cs.account.NamedEntry;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Arrays;
/*     */ import java.util.Collection;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ import org.junit.Assert;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Verify
/*     */ {
/*     */   public static void verifySameId(NamedEntry entry1, NamedEntry entry2)
/*     */     throws Exception
/*     */   {
/*  36 */     Assert.assertNotNull(entry1);
/*  37 */     Assert.assertNotNull(entry2);
/*  38 */     Assert.assertEquals(entry1.getId(), entry2.getId());
/*     */   }
/*     */   
/*     */   public static void verifySameEntry(NamedEntry entry1, NamedEntry entry2) throws Exception
/*     */   {
/*  43 */     verifySameId(entry1, entry2);
/*  44 */     Assert.assertEquals(entry1.getName(), entry2.getName());
/*     */   }
/*     */   
/*     */   public static void verifyEntries(List<NamedEntry> list, NamedEntry[] entries, boolean checkCount)
/*     */     throws Exception
/*     */   {
/*     */     try
/*     */     {
/*  52 */       if (checkCount) {
/*  53 */         Assert.assertEquals(list.size(), entries.length);
/*     */       }
/*  55 */       Set<String> ids = new HashSet();
/*  56 */       for (NamedEntry entry : list) {
/*  57 */         ids.add(entry.getId());
/*     */       }
/*  59 */       for (NamedEntry entry : entries) {
/*  60 */         Assert.assertTrue(ids.contains(entry.getId()));
/*  61 */         ids.remove(entry.getId());
/*     */       }
/*     */       
/*     */ 
/*  65 */       if (checkCount) {
/*  66 */         Assert.assertEquals(ids.size(), 0L);
/*     */       }
/*     */     } catch (AssertionError e) {
/*  69 */       System.out.println();
/*  70 */       System.out.println("===== verifyEntries failed =====");
/*  71 */       System.out.println("Message: " + e.getMessage());
/*     */       
/*  73 */       System.out.println();
/*  74 */       System.out.println("list contains " + list.size() + " entries:");
/*  75 */       for (NamedEntry entry : list) {
/*  76 */         System.out.println("    " + entry.getName());
/*     */       }
/*     */       
/*  79 */       System.out.println();
/*  80 */       System.out.println("entries contains " + entries.length + " entries:");
/*  81 */       for (NamedEntry entry : entries) {
/*  82 */         System.out.println("    " + entry.getName());
/*     */       }
/*     */       
/*  85 */       System.out.println();
/*  86 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static void verifyEntriesById(List<NamedEntry> list, String[] names, boolean checkCount)
/*     */     throws Exception
/*     */   {
/*  95 */     Set<String> idsInList = new HashSet();
/*  96 */     for (NamedEntry entry : list) {
/*  97 */       idsInList.add(entry.getId());
/*     */     }
/*  99 */     verifyEntries(idsInList, names, checkCount);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public static void verifyEntriesByName(List<NamedEntry> list, String[] names, boolean checkCount)
/*     */     throws Exception
/*     */   {
/* 107 */     Set<String> namesInList = new HashSet();
/* 108 */     for (NamedEntry entry : list) {
/* 109 */       namesInList.add(entry.getName());
/*     */     }
/* 111 */     verifyEntries(namesInList, names, checkCount);
/*     */   }
/*     */   
/*     */ 
/*     */   public static void verifyEntries(Set<String> list, String[] names, boolean checkCount)
/*     */     throws Exception
/*     */   {
/*     */     try
/*     */     {
/* 120 */       if (checkCount) {
/* 121 */         Assert.assertEquals(names.length, list.size());
/*     */       }
/*     */       
/* 124 */       for (String name : names) {
/* 125 */         Assert.assertTrue(list.contains(name));
/*     */       }
/*     */     } catch (AssertionError e) {
/* 128 */       System.out.println();
/* 129 */       System.out.println("===== verifyEntries failed =====");
/* 130 */       System.out.println("Message: " + e.getMessage());
/*     */       
/* 132 */       System.out.println();
/* 133 */       System.out.println("list contains " + list.size() + " entries:");
/* 134 */       for (String name : list) {
/* 135 */         System.out.println("    " + name);
/*     */       }
/*     */       
/* 138 */       System.out.println();
/* 139 */       System.out.println("entries contains " + names.length + " entries:");
/* 140 */       for (String name : names) {
/* 141 */         System.out.println("    " + name);
/*     */       }
/*     */       
/* 144 */       System.out.println();
/* 145 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */   public static void verifyEquals(Collection<String> expected, Collection<String> actual) throws Exception
/*     */   {
/*     */     try {
/* 152 */       Assert.assertEquals(expected.size(), actual.size());
/*     */       
/* 154 */       for (String entry : expected)
/*     */       {
/* 156 */         if (!actual.contains(entry)) {
/* 157 */           System.out.println("missing entry: " + entry);
/*     */         }
/* 159 */         Assert.assertTrue(actual.contains(entry));
/*     */       }
/*     */     } catch (AssertionError e) {
/* 162 */       dump(e, expected, actual);
/* 163 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */   public static void verifyEquals(Set<String> expected, String[] actual) throws Exception
/*     */   {
/* 169 */     verifyEquals(expected, Sets.newHashSet(Arrays.asList(actual)));
/*     */   }
/*     */   
/*     */   public static void verifyEquals(List<String> expected, List<String> actual) throws Exception
/*     */   {
/*     */     try {
/* 175 */       Assert.assertEquals(expected.size(), actual.size());
/*     */       
/* 177 */       for (int i = 0; i < expected.size(); i++) {
/* 178 */         Assert.assertEquals(expected.get(i), actual.get(i));
/*     */       }
/*     */     } catch (AssertionError e) {
/* 181 */       dump(e, expected, actual);
/* 182 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */   public static void verifyEquals(List<String> expected, String[] actual) throws Exception
/*     */   {
/* 188 */     verifyEquals(expected, Arrays.asList(actual));
/*     */   }
/*     */   
/*     */   private static void dump(AssertionError e, Collection<String> expected, Collection<String> actual) {
/* 192 */     System.out.println();
/* 193 */     System.out.println("===== verifyEquals failed =====");
/* 194 */     System.out.println("Message: " + e.getMessage());
/*     */     
/* 196 */     System.out.println();
/* 197 */     System.out.println(String.format("expected (size=%d)", new Object[] { Integer.valueOf(expected.size()) }));
/* 198 */     for (String str : expected) {
/* 199 */       System.out.println("    " + str);
/*     */     }
/*     */     
/* 202 */     System.out.println();
/* 203 */     System.out.println(String.format("actual (size=%d)", new Object[] { Integer.valueOf(actual.size()) }));
/* 204 */     for (String str : actual) {
/* 205 */       System.out.println("    " + str);
/*     */     }
/*     */     
/* 208 */     System.out.println();
/*     */   }
/*     */   
/*     */   public static void verifyEquals(Set<String> expected, List<NamedEntry> actual) {
/*     */     try {
/* 213 */       Assert.assertEquals(expected.size(), actual.size());
/*     */       
/* 215 */       for (NamedEntry entry : actual) {
/* 216 */         Assert.assertTrue(expected.contains(entry.getName()));
/*     */       }
/*     */     } catch (AssertionError e) {
/* 219 */       System.out.println();
/* 220 */       System.out.println("===== verifyEquals failed =====");
/* 221 */       System.out.println("Message: " + e.getMessage());
/*     */       
/* 223 */       System.out.println();
/* 224 */       System.out.println(String.format("expected (size=%d)", new Object[] { Integer.valueOf(expected.size()) }));
/* 225 */       for (String name : expected) {
/* 226 */         System.out.println("    " + name);
/*     */       }
/* 228 */       System.out.println();
/* 229 */       System.out.println(String.format("actual (size=%d)", new Object[] { Integer.valueOf(actual.size()) }));
/* 230 */       for (NamedEntry entry : actual) {
/* 231 */         System.out.println("    " + entry.getName());
/*     */       }
/* 233 */       System.out.println();
/* 234 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */   public static void verifyEquals(List<? extends NamedEntry> expected, List<? extends NamedEntry> actual, boolean orderMatters)
/*     */   {
/*     */     try {
/* 241 */       if (expected == null) {
/* 242 */         expected = new ArrayList();
/*     */       }
/*     */       
/* 245 */       int size = expected.size();
/*     */       
/* 247 */       Assert.assertEquals(expected.size(), actual.size());
/*     */       
/* 249 */       List<String> expectedIds = Lists.newArrayList();
/* 250 */       List<String> expectedNames = Lists.newArrayList();
/* 251 */       for (NamedEntry entry : expected) {
/* 252 */         expectedIds.add(entry.getId());
/* 253 */         expectedNames.add(entry.getName());
/*     */       }
/*     */       
/* 256 */       List<String> actualIds = Lists.newArrayList();
/* 257 */       List<String> actualNames = Lists.newArrayList();
/* 258 */       for (NamedEntry entry : actual) {
/* 259 */         actualIds.add(entry.getId());
/* 260 */         actualNames.add(entry.getName());
/*     */       }
/*     */       
/* 263 */       for (int i = 0; i < size; i++) {
/* 264 */         if (orderMatters) {
/* 265 */           Assert.assertEquals(expectedIds.get(i), actualIds.get(i));
/* 266 */           Assert.assertEquals(expectedNames.get(i), actualNames.get(i));
/*     */         } else {
/* 268 */           Assert.assertTrue(actualIds.contains(expectedIds.get(i)));
/* 269 */           Assert.assertTrue(actualNames.contains(expectedNames.get(i)));
/*     */         }
/*     */       }
/*     */     }
/*     */     catch (AssertionError e) {
/* 274 */       System.out.println();
/* 275 */       System.out.println("===== verifyEquals failed =====");
/* 276 */       System.out.println("Message: " + e.getMessage());
/*     */       
/* 278 */       System.out.println();
/* 279 */       System.out.println(String.format("expected (size=%d)", new Object[] { Integer.valueOf(expected.size()) }));
/* 280 */       for (NamedEntry entry : expected) {
/* 281 */         System.out.println("    " + entry.getName() + " (" + entry.getId() + ")");
/*     */       }
/*     */       
/* 284 */       System.out.println();
/* 285 */       System.out.println(String.format("actual (size=%d)", new Object[] { Integer.valueOf(actual.size()) }));
/* 286 */       for (NamedEntry entry : actual) {
/* 287 */         System.out.println("    " + entry.getName() + " (" + entry.getId() + ")");
/*     */       }
/*     */       
/* 290 */       System.out.println();
/* 291 */       throw e;
/*     */     }
/*     */   }
/*     */   
/*     */   public static String makeResultStr(Object... objs) {
/* 296 */     StringBuilder sb = new StringBuilder();
/* 297 */     for (Object obj : objs) {
/* 298 */       if (sb.length() > 0) {
/* 299 */         sb.append(":");
/*     */       }
/* 301 */       if (obj != null) {
/* 302 */         if ((obj instanceof Collection)) {
/* 303 */           for (Object o : (Collection)obj) {
/* 304 */             sb.append("(");
/* 305 */             sb.append(o.toString());
/* 306 */             sb.append(")");
/*     */           }
/*     */         } else {
/* 309 */           sb.append(obj.toString());
/*     */         }
/*     */       } else {
/* 312 */         sb.append("null");
/*     */       }
/*     */     }
/* 315 */     return sb.toString();
/*     */   }
/*     */   
/*     */   public static void appendResultStr(StringBuilder appendTo, Object... objs) {
/* 319 */     if (appendTo.length() > 0) {
/* 320 */       appendTo.append(":");
/*     */     }
/* 322 */     appendTo.append(makeResultStr(objs));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/Verify.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */